﻿using DataServer.CommonLib.Models.DataBase;
using FluentValidation;

namespace DataServer.CommonLib.Validators
{
    public class DatabaseEditValidator: AbstractValidator<DatabaseEditRequestDto>
    {
        public DatabaseEditValidator()
        {
            //RuleFor(p => p.DatabaseName)
            //        .NotEmpty()
            //        .WithMessage("角色编码为必填项");

        }

        public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
        {
            var result =
                await ValidateAsync(ValidationContext<DatabaseEditRequestDto>.CreateWithOptions((DatabaseEditRequestDto)model,
                    x => x.IncludeProperties(propertyName)));
            if (result.IsValid)
                return Array.Empty<string>();
            return result.Errors.Select(e => e.ErrorMessage);
        };
    }
}